<?php
namespace Admin\Controller;
use Think\Controller;
class SystemController extends CommonController {
	public function set(){
		$m = M('system');
		$res = $m -> where('sid=%d',[1]) -> find();
		// dump($res);die;
		$this -> assign('res',$res);
		$this -> display();
	}

	public function param(){
		$data = M('param') -> where('id=%d',[1]) -> find();
		$res = M('newkg') -> where('id=%d',[1]) -> find();
		$res1 = M('cf') -> field('points_num1') -> order('cf_id desc') -> limit(1) -> find();
		$this -> assign('points_num1',$res1['points_num1']);
		$this -> assign('newkg',$res);
		$this -> assign('data',$data);
		$this -> display();
	}

	public function edit1(){
		$data = ['system_sell_time'=>I('post.system_sell_time'),'wname'=>I('post.wname'),'wtitle'=>I('post.wtitle'),'is_close'=>I('post.is_close'),'desc'=>I('post.desc'),'is_closed'=>I('post.desc'),'zhuanhuan'=>I('post.zhuanhuan'),'zhuanzhang'=>I('post.zhuanzhang')];
		$mod = M('system');
		//dump($data);
		$mod -> startTrans();
		$res = $mod -> data($data) -> where('sid=%d',[1])  -> save();
		//封装日志
			$admin_log = M('admin_log');
			$ad_log['user_name'] = $_SESSION['admin']['user_name'];
			$ad_log['log_time'] = time();
			$ad_log['user_id'] = $_SESSION['admin']['user_id'];
			$ad_log['log_info'] = '系统参数修改操作';
			$ad_log['ip_address']= get_client_ip();
			$res2 = $admin_log -> add($ad_log);
		if($res && $res2>0){
			$this -> success('修改成功');
		}else{
			$this -> error('修改失败');
		}
	}


	public function edit2(){
		$data1['param10'] = I('post.param10');
		$data1['param11'] = I('post.param11');
		$data1['param1'] = I('post.param1');
		$data1['param2'] = I('post.param2');
		$data1['maxsell'] = I('post.maxsell');
		$data1['param8_1'] = I('post.param8_1');
		$data1['param8_2'] = I('post.param8_2');
		$data1['param12'] = I('post.param12');
		$data1['param3'] = I('post.param3');
		$data1['txsjstart'] = I('post.txsjstart');
		$data1['txsjend'] = I('post.txsjend');
		$data1['nowetotal'] = I('post.nowetotal');
		$data1['sys'] = I('post.sys');
		$data1['jys'] = I('post.jys');
		$data1['param4'] = I('post.param4');
		$data1['param7'] = I('post.param7');
		$data1['param5'] = I('post.param5');
		$data1['param6'] = I('post.param6');
		// M() -> startTrans();
		//修改param表
		$res1 = M('param') -> data($data1) -> where('id=%d',[1]) -> save();
// echo M() -> _SQL();die;

		$data2['dongtaishui'] = I('post.dongtaishui');
		$data2['cishanshui'] = I('post.cishanshui');
		$data2['kaiguan'] = I('post.kaiguan');
		$data2['yijiankg'] = I('post.yijiankg');
		//修改newkg
		$res2 = M('newkg') -> data($data2) -> where('id=%d',[1]) -> save();
				// echo M() -> _SQL();

		//修改K_log表
		$k = M() -> query('select cf_id from zx_cf order by cf_id desc limit 0,1');
		// echo M() -> _SQL();
		$res3 = M() -> execute('update zx_cf set points_num1 = '.I('post.points_num1').' where cf_id = %d',$k[0]['cf_id']);
		// echo M() -> _SQL();DIE;
		$this -> success('修改成功');
		
	}
}